/*
 * @Author: 耿远风
 * @Date: 2020-10-16 18:01:33
 * @LastEditors: 耿远风
 * @LastEditTime: 2020-10-16 18:03:18
 * @Description: 
 */
import { BaseModel } from '../../base/base/BaseModel';
import { prop, pre } from 'typegoose';
import { IImageInfo, ImageStore } from 'src/base/image/image.entity';
// import { async } from 'rxjs';

@pre<GoodModel>('save', async function(next) {
    // if (this.cover) {
    //     try{
    //         if (typeof this.cover == 'string') {
    //             let cover:string=this.cover;
    //             this.cover= await ImageStore.findOne({src:cover});
    //         }
    //     }catch(err){}
    // }
    console.log('=====执行了pre=====');
    console.log('执行了pre');
    console.log('=====执行了pre=====');
    next();
})
export class GoodModel extends BaseModel {
    // 封面
    @prop() cover?: IImageInfo;
    // 名称
    @prop() name?: string;
    // 简介
    @prop() content?: string;
    // 名称
    @prop() details?: string;
    // 价格，分
    @prop({ default: 0 })
    price!: number;
    // 会员价格，分
    @prop({ default: 0 })
    vipPrice!: number;
    // 类型
    @prop({ required: true })
    category!: string;
    // 是否上架
    @prop({ default: true })
    isFocus?: boolean;
}
export const Good = new GoodModel().getModelForClass(GoodModel, {
    schemaOptions: {
        timestamps: true,
        versionKey: false,
    },
});
